package src.dynamic_programming;

/**
 * @author starsea
 * @date 2024-09-17 14:50
 */

public class Test14 {
    public static void main(String[] args) {
        int[] arr={9,4,2,10,7,8,8,1,9};
        int c=maxTurbulenceSize(arr);
    }
    public static int maxTurbulenceSize(int[] arr) {
        int n=arr.length;
        if(n<2)
        {
            return n;
        }
        int[] f=new int[n];
        int[] g=new int[n];
        int max=0;
        for(int i=0;i<n;i++)
        {
            f[i]=g[i]=1;
        }
        for(int i=1;i<n;i++)
        {
           if(arr[i-1]<arr[i])
           {
               f[i]=g[i-1]+1;
           }
           if(arr[i-1]>arr[i])
           {
               g[i]=f[i-1]+1;
           }
           max=Math.max(max,Math.max(g[i],f[i]));
        }
        return max;
    }
}
